﻿using System;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class ScenarioProtectRecord : WorksheetLevelRecord
    {
        private ushort _fScenProtect;

        public ScenarioProtectRecord(ushort value)
        {
            this._fScenProtect = value;
        }

        public ScenarioProtectRecord()
        {
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.ScenarioProtect; }
        }

        internal override void Apply(BiffReaderWorksheetContext context)
        {
            if (this._fScenProtect != 0)
                context.Worksheet.EnsureProtection().Scenarios = true;
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            context.Write(_fScenProtect);
        }

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            _fScenProtect = context.ReadUInt16();
            Contract.Assert(_fScenProtect == 0 || _fScenProtect == 1);


        }
    }
}